package com.ruoyi.project.poem.goodsarticle.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.poem.goodsarticle.domain.GoodsArticle;
import com.ruoyi.project.poem.goodsarticle.mapper.GoodsArticleMapper;
import com.ruoyi.project.poem.goodsarticle.service.IGoodsArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 好物推文Service业务层处理
 *
 * @author shixiangwen
 * @date 2021-06-24
 */
@Service
@DataSource(DataSourceType.POEM)
public class GoodsArticleServiceImpl implements IGoodsArticleService {
    @Autowired
    private GoodsArticleMapper goodsArticleMapper;

    /**
     * 查询好物推文
     *
     * @param id 好物推文ID
     * @return 好物推文
     */
    @Override
    public GoodsArticle selectGoodsArticleById(Long id) {
        return goodsArticleMapper.selectGoodsArticleById(id);
    }

    /**
     * 查询好物推文列表
     *
     * @param goodsArticle 好物推文
     * @return 好物推文
     */
    @Override
    public List<GoodsArticle> selectGoodsArticleList(GoodsArticle goodsArticle) {
        return goodsArticleMapper.selectGoodsArticleList(goodsArticle);
    }

    /**
     * 新增好物推文
     *
     * @param goodsArticle 好物推文
     * @return 结果
     */
    @Override
    public int insertGoodsArticle(GoodsArticle goodsArticle) {
        goodsArticle.setCreateTime(DateUtils.getNowDate());
        goodsArticle.setCreateUser(ShiroUtils.getLoginName());
        return goodsArticleMapper.insertGoodsArticle(goodsArticle);
    }

    /**
     * 修改好物推文
     *
     * @param goodsArticle 好物推文
     * @return 结果
     */
    @Override
    public int updateGoodsArticle(GoodsArticle goodsArticle) {
        goodsArticle.setUpdateTime(DateUtils.getNowDate());
        return goodsArticleMapper.updateGoodsArticle(goodsArticle);
    }

    /**
     * 删除好物推文对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteGoodsArticleByIds(String ids) {
        return goodsArticleMapper.deleteGoodsArticleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除好物推文信息
     *
     * @param id 好物推文ID
     * @return 结果
     */
    @Override
    public int deleteGoodsArticleById(Long id) {
        return goodsArticleMapper.deleteGoodsArticleById(id);
    }
}
